﻿using System;
using System.Collections.Generic;
using System.Text;

namespace EasyStudy.Logic
{
    public class EbbTaskMgr
    {
        public EbbTaskMgr()
        {
            circle = Time.TimeMgr.GetTaskCircle();
        }

        public List<long> Circle
        {
            get { return circle; }
        }

        public EbbinghausTask CreateAEbbTask(string subject) 
        {
            return CreateAEbbTask(subject, "","", DateTime.Now);
        }

        public EbbinghausTask CreateAEbbTask(string subject, string comment, string type)
        {
            return CreateAEbbTask(subject, comment, type, DateTime.Now);
        }

        public EbbinghausTask CreateAEbbTask(string subject, string comment, string type,
            DateTime startTime) 
        {
            EbbinghausTask eTask = new EbbinghausTask();

            eTask.CreateTime = startTime;
            eTask.UpdateTime = DateTime.MinValue;
            eTask.Subject = subject;
            eTask.Comment = comment;
            eTask.Type = type;

            long startTimeTickes = startTime.Ticks;              // 开始的时间戳
            long nextRemindTickes = startTimeTickes;

            // 初始化Remind时间表
            foreach (long interval in circle)
            {
                nextRemindTickes = startTimeTickes + interval * 1000 * 10000;
                // 转换到DateTime
                DateTime dt = new DateTime(nextRemindTickes);
                eTask.RemindTimes.Add(dt);
            }
            eTask.NextTime = eTask.RemindTimes[0];

            return eTask;
        }

        private List<long> circle;
    }
}
